<?php
class basketitemdao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	public function getbyid($id){
		$this->db->select('*');
		$this->db->from('basket_item');
		$this->db->where('basket_item_id',$id);
		$query = $this->db->get();
		$res = $query->row();
		return $res;
	}
	
	public function get_all(){
		$this->db->select('*');
		$this->db->from('basket_item');
		$query = $this->db->get();
		$res = $query->result();
		return $res;
	}
	
	public function insert($market_item_id,$transaction_id,$quantity){
		$data = array(
				'market_item_id' => $market_item_id,
				'transaction_id' => $transaction_id,
				'quantity' => $quantity,
		);
		$str = $this->db->insert_string('basket_item', $data);
		$res = $this->db->query($str);
		return $res;
	}
	
	public function del($basket_item_id) {
		if (intval($basket_item_id) > 0) {
			$this->db->where('basket_item_id',$basket_item_id);
			$this->db->delete('basket_item');
			return ($this->db->affected_rows() == 1) ? TRUE : FALSE;
		}
		return false;
	}
	
	public function insert_list($json_data){
		
		$data = json_decode($json_data, TRUE);
		
		foreach ($sub_data as $data){
			$sub_data = array(
					'market_item_id' => $sub_data['market_item_id'],
					'transaction_id' => $sub_data['transaction_id'],
					'basket_item_id' => $sub_data['basket_item_id'],
					'quantity' => $sub_data['quantity']
			);
			return $sub_data;
			$this->db->insert('basket_item', $sub_data);
			
				
		}
		return true;
	}
}
?>